package com.itnoob.service.impl.decorator;

import com.itnoob.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @author zhoujun  日志和权限的装饰者类: 装饰日志和权限
 * @date 2024/12/7 10:22
 */
@Service("logAndAuthUserService")
public class LogAndAuthUserServiceDecorator extends UserServiceDecorator{

    //日志装饰者的引用
    private LogUserServiceDecorator logUserServiceDecorator;


    //权限装饰者的引用
    private AuthUserServiceDecorator authUserServiceDecorator;

    //通过构造器注入日志和权限的装饰者,并使用@Autowired注解让spring自动为我们找到合适的bean对象
    @Autowired
    public LogAndAuthUserServiceDecorator(UserService userService, LogUserServiceDecorator logUserServiceDecorator, AuthUserServiceDecorator authUserServiceDecorator) {
        //调用父类的构造方法,传入一个任意的装饰者对象
        super(logUserServiceDecorator);
        this.logUserServiceDecorator = logUserServiceDecorator;
        this.authUserServiceDecorator = authUserServiceDecorator;
    }

    @Override
    public String getUserName(int id) {
        //调用日志的装饰者方法,实现日志功能
        logUserServiceDecorator.getUserName(id);
        //调用权限的装饰者方法,实现权限功能,并返回用户对象
        return authUserServiceDecorator.getUserName(id);
    }
}
